/*

  json_true.h
  Shan.Lib

 Copyright (c) 2013, Sung-Han Park
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:

 1. Redistributions of source code must retain the above copyright notice, this
 list of conditions and the following disclaimer.
 2. Redistributions in binary form must reproduce the above copyright notice,
 this list of conditions and the following disclaimer in the documentation
 and/or other materials provided with the distribution.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

#ifndef _Shan_JSON_json_true_h_
#define _Shan_JSON_json_true_h_

#include "json_exception.h"
#include "json_value.h"

namespace shan {
	namespace json {
		class true_value : public json::value {
		public:
			true_value() {}
			virtual ~true_value() {}

			virtual int to_int() {
				return 1;
			}

			virtual long to_long() {
				return 1l;
			}

			virtual long long to_long_long() {
				return 1ll;
			}

			virtual float to_float() {
				return 1.0f;
			}

			virtual double to_double() {
				return 1.0;
			}

			virtual bool to_bool() {
				return true;
			}

			virtual bool is_null() {
				return false;
			}

			virtual std::string to_json() const {
				return std::string("true");
			}

			virtual std::string to_string() const {
				return to_json();
			}

		protected:
			virtual void internal_parse(std::istream& is) {
				if ((is.get() == 't') &&
					(is.get() == 'r') &&
					(is.get() == 'u') &&
					(is.get() == 'e'))
					return;
				else
					throw json::exception("Invalid syntax was found. The expected value was 'true'.");
			}
		};
	}
}

#endif
